<template>
  <div>
    <Card size="small" :bordered="false" class="w-4/4 w-full !mt-0 !rounded-lg !p-6px">
      <template #title>
        <div class="flex items-center cursor-pointer">
          <span>传输消息</span>
          <Icon icon="material-symbols:info" title="来自设备的所有消息" />
        </div>
      </template>
      <div ref="chartRef" class="h-170px w-full mt-1">></div>
    </Card>
  </div>
</template>

<script setup lang="ts">
  import { Card } from 'ant-design-vue';
  import Icon from '/@/components/Icon';
  import { useECharts } from '/@/hooks/web/useECharts';
  import { ref, watch, Ref } from 'vue';
  import { basicProps } from './props';
  let props = defineProps({
    ...basicProps,
    echartsList: {
      type: Array,
      default: () => [],
    },
  });
  watch(
    () => props.echartsList,
    (nVal: any) => {
      setOptions({
        tooltip: {
          //   trigger: "item", //默认效果
          //柱状图加阴影
          trigger: 'axis',
          axisPointer: {
            type: 'shadow',
            label: {
              show: true,
            },
          },
        },
        grid: {
          top: '10%',
          left: '0%',
          right: '0%',
          bottom: '0%',
          containLabel: true,
        },
        xAxis: {
          type: 'time',
          splitLine: {
            show: true,
            interval: 'auto',
            lineStyle: {
              type: 'dashed',
              color: ['#cfcfcf'],
            },
          },
          axisTick: {
            show: false,
          },
          axisLine: {
            lineStyle: {
              color: '#cfcfcf',
            },
          },
          axisLabel: {
            fontSize: 7,
            color: '#9e9d9f',
          },
        },
        yAxis: [
          {
            type: 'value',
            splitLine: {
              show: true,
              lineStyle: {
                type: 'dashed',
                color: ['#cfcfcf'],
              },
            },
            axisTick: {
              show: false,
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: '#cfcfcf',
              },
            },
            axisLabel: {
              fontSize: 8,
              color: '#9e9d9f',
            },
          },
        ],
        series: [
          {
            itemStyle: {
              color: '#31c2b0',
            },
            name: '传输消息',
            data: nVal,
            type: 'bar',
          },
        ],
      });
    },
    {
      deep: true,
    },
  );
  const chartRef = ref<HTMLDivElement | null>(null);
  const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
</script>
